home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / RECORDS.SWG / 0005_RECSORT.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  89 lines

  1. {
  2.  ... would anyone know how-to sort a Record With 5 thing in it one of
  3.  which is "NAME"...I want to sort each Record in the Array by name and
  4.  can't figure it out....my Array name is LabelS and my Record name is
  5.  SofT...
  6. }
  7.  
  8. Program sort_Records;
  9.  
  10. Type
  11.   index_Type = 1..100;
  12.   soft_Type = Record
  13.                 name,
  14.                 street,
  15.                 city: String[20];
  16.                 state: String[2];
  17.                 zip: Integer
  18.               end; { Record }
  19.   Labels_Type = Array[index_Type] of soft_Type;
  20.  
  21. Var
  22.   Labels: Labels_Type; { an Array of Records }
  23.   index,
  24.   count: index_Type;
  25.   f: Text; { a File on disk holding your Records, we assume 100 }
  26.  
  27. { ******************************************** }
  28. Procedure get_Records(Var f: Text;
  29.                       Var Labels: Labels_Type); Var
  30.   counter: index_Type;
  31.  
  32. begin { get_Records }
  33.   For counter := 1 to 100 do
  34.     begin
  35.       With Labels[counter] do
  36.         readln(f, name, street, city, state, zip);
  37.     end;
  38. end;  { get_Records }
  39.  
  40. { ******************************************** }
  41. Procedure sort_em(Var Labels: Labels_Type);
  42.  
  43. Var
  44.   temp: soft_Type;    { a Single Record }
  45.   counter,
  46.   counter2,
  47.   min_index: Integer;
  48.  
  49. begin { sort_em }
  50.   For counter := 1 to 99 do { 99 not 100 }
  51.     begin
  52.       min_index := counter;
  53.       For counter2 := counter + 1 to 100 do
  54.         if Labels[counter2].name < Labels[counter].name
  55.           then
  56.             min_index := counter;
  57.       temp := Labels[min_index];
  58.       Labels[min_index] := Labels[counter];
  59.       Labels[counter] := temp
  60.     end;
  61. end;  { sort_em }
  62.  
  63. { ******************************************** }
  64.  
  65. Procedure Write_Labels(Var Labels: Labels_Type;
  66.                        Var f: Text);
  67. Var
  68.   counter: index_Type;
  69.  
  70. begin { Write_Labels }
  71.   For counter := 1 to 100 do
  72.     begin
  73.       With Labels[counter] do
  74.         Writeln(f, name, street, city, state, zip);
  75.     end;
  76. end;  { Write_Labels }
  77.  
  78. { ******************************************** }
  79.  
  80. begin { main }
  81.   assign(f, 'DATAFile.DAT'); { or whatever it is on your disk }
  82.   reset(f);
  83.   get_Records(f, Labels);
  84.   sort_em(Labels);
  85.   reWrite(f);
  86.   Write_Labels(Labels, f);
  87.   close(f)
  88. end. { main }
  89.